package com.flying.flow.model;

import java.util.Date;
import java.util.List;

import com.flying.common.util.Codes;
import com.flying.framework.annotation.ConstantEnum;
import com.flying.framework.annotation.Param;
import com.flying.framework.annotation.Property;
import com.flying.framework.annotation.ServiceField;
import com.flying.framework.annotation.ServiceFieldParam;
import com.flying.framework.data.Data;
import com.flying.framework.data.DataSerializable;
import com.flying.framework.metadata.Meta;

@SuppressWarnings("serial")
@Meta(id="f_flow_definition",title="", table="f_flow_definition", primaryKeys={"flow_def_id"})
public class FlowDefinition extends Data implements DataSerializable {
	public final static String ENTITY_NAME = "f_flow_definition";
	
	public final static String CREATE_TIME = "create_time";
	public final static String CREATOR = "creator";
	public final static String FLOW_DEF_ID = "flow_def_id";
	public final static String NAME = "name";
	public final static String CODE = "code";
	public final static String ORG_CODE = "org_code";
	public final static String BUSINESS_TYPE = "business_type";
	public final static String PUBLISH_STATUS = "publish_status";
	public final static String PUBLISH_TIME = "publish_time";
	public final static String PUBLISHER = "publisher";
	public final static String REMARKS = "remarks";
	public final static String UPDATE_TIME = "update_time";
	public final static String UPDATOR = "updator";
	public final static String VERSION = "version";

	public enum PublishStatus implements ConstantEnum<Integer> {
		CREATING(0, "待发布"), PUBLISHED(8, "已发布"), INVALID(9, "已禁用");
		
		public final int status;
		public final String remarks;
		
		PublishStatus(int status, String remarks) {
			this.status = status;
			this.remarks = remarks;
		}
		@Override
		public Integer value() {
			return status;
		}
		@Override
		public String text() {
			return remarks;
		}
	}
	
	@Param(value=CREATE_TIME,   required=false,   maxlength=0,	desc="创建时间" )
	private Date createTime;
	
	@Param(value=ORG_CODE,   required=false,   maxlength=0,	desc="机构" )
	private String orgCode;
	
	@Param(value=BUSINESS_TYPE,   required=false,   maxlength=0,	desc="适用业务类型" )
	private String businessType;
	
	@Param(value=CREATOR,   required=false,   maxlength=100,	desc="创建人" )
	private String creator;
	
	@Param(value=FLOW_DEF_ID,   required=true,   maxlength=0,	desc="流程定义ID" , generator=Codes.AUTO_INCREMENT, 
			props= {@Property(name="type",value="hidden")})
	private Long flowDefId;
	
	@Param(value=NAME,   required=false,   maxlength=100,	desc="名称" )
	private String name;
	
	@Param(value=CODE,   required=false,   maxlength=100,	desc="代码" )
	private String code;
	
	@Param(value=PUBLISH_STATUS,   required=false,   maxlength=0,	desc="发布状态" )
	private Integer publishStatus;
	
	@Param(value=PUBLISH_TIME,   required=false,   maxlength=0,	desc="发布时间" )
	private Date publishTime;
	
	@Param(value=PUBLISHER,   required=false,   maxlength=100,	desc="发布人" )
	private String publisher;
	
	@Param(value=REMARKS,   required=false,   maxlength=1000,	desc="说明" )
	private String remarks;
	
	@Param(value=UPDATE_TIME,   required=false,   maxlength=0,	desc="修改时间" )
	private Date updateTime;
	
	@Param(value=UPDATOR,   required=false,   maxlength=100,	desc="修改人" )
	private String updator;
	
	@Param(value=VERSION,   required=true,   maxlength=0,	desc="流程版本" )
	private Integer version;

	@ServiceField(serviceId="NodeService:findByFlowDefinitionId", lazyLoad=false, valueAttribute="rows", 
			params={@ServiceFieldParam(param=Node.FLOW_DEF_ID, value="$"+FLOW_DEF_ID)})
	@Param(value="nodes",   required=false,   desc="流程节点", ignored=true)
	private List<Node> nodes;

	@ServiceField(serviceId="NodeTransitionService:findByFlowDefinitionId", lazyLoad=false, valueAttribute="rows", 
			params={@ServiceFieldParam(param=NodeTransition.FLOW_DEF_ID, value="$"+FLOW_DEF_ID)})
	@Param(value="transitions",   required=false,   desc="流程节点", ignored=true )
	private List<NodeTransition> transitions;
	
	public Date getCreateTime() {
		return this.createTime;
	}
	
	public void setCreateTime(Date createTime) {
		this.createTime = createTime;
	}
	
	public String getCreator() {
		return this.creator;
	}
	
	public void setCreator(String creator) {
		this.creator = creator;
	}
	
	public Long getFlowDefId() {
		return this.flowDefId;
	}
	
	public void setFlowDefId(Long flowDefId) {
		this.flowDefId = flowDefId;
	}
	
	public String getName() {
		return this.name;
	}
	
	public void setName(String name) {
		this.name = name;
	}
	
	public String getCode() {
		return code;
	}

	public void setCode(String code) {
		this.code = code;
	}

	public Integer getPublishStatus() {
		return publishStatus;
	}

	public void setPublishStatus(Integer publishStatus) {
		this.publishStatus = publishStatus;
	}

	public Date getPublishTime() {
		return this.publishTime;
	}
	
	public void setPublishTime(Date publishTime) {
		this.publishTime = publishTime;
	}
	
	public String getPublisher() {
		return this.publisher;
	}
	
	public void setPublisher(String publisher) {
		this.publisher = publisher;
	}
	
	public String getRemarks() {
		return this.remarks;
	}
	
	public void setRemarks(String remarks) {
		this.remarks = remarks;
	}
	
	public Date getUpdateTime() {
		return this.updateTime;
	}
	
	public void setUpdateTime(Date updateTime) {
		this.updateTime = updateTime;
	}
	
	public String getUpdator() {
		return this.updator;
	}
	
	public void setUpdator(String updator) {
		this.updator = updator;
	}
	
	public Integer getVersion() {
		return this.version;
	}
	
	public void setVersion(Integer version) {
		this.version = version;
	}

	public String getOrgCode() {
		return orgCode;
	}

	public void setOrgCode(String org) {
		this.orgCode = org;
	}

	public String getBusinessType() {
		return businessType;
	}

	public void setBusinessType(String businessType) {
		this.businessType = businessType;
	}

	public List<Node> getNodes() {
		return nodes;
	}

	public List<NodeTransition> getTransitions() {
		return transitions;
	}
	
}